#!/usr/bin/python
# Converts Fastq file to Fasta and Qual files
# Usage: python convertFastq2FastaQual.py file.fastq file.fasta
# Note: Needs to work on the script to print Qual files (not printing this yet)

import sys
import re
from Bio import SeqIO
from Bio.SeqIO.QualityIO import FastqGeneralIterator

untrimmed = sys.argv[1]
trimmedFasta = sys.argv[2]

fastahandle = open(trimmedFasta, "w")
min_length = 10
for title, seq, qual in FastqGeneralIterator(open(untrimmed)) :
    qual = qual.rstrip("B") #Remove any trailing B characters
    length = len(qual)
    if length >= min_length:
        seq = seq[:length] #trim to match
        #fastahandle.write("@%s\n%s\n+\n%s\n" % (title, seq, qual))
        fastahandle.write(">%s\n%s\n" % (title, seq))
fastahandle.close()
